package com.kool.kmetrics.constant;

import lombok.Getter;

import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;

@Getter
public enum DateDimEnum {
    Day(1, "日"),
    Month(2, "月");

    DateDimEnum(int code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    /**
     * 码
     */
    int code;
    /**
     * 描述
     */
    String desc;

    public static Map<Integer, DateDimEnum> codeToEnum = Stream.of(DateDimEnum.values()).collect(Collectors.toMap(DateDimEnum::getCode, self -> self));

    /**
     * 获取描述
     *
     * @param code
     * @return
     */
    public static String getDesc(int code) {
        return codeToEnum.get(code) == null ? null : codeToEnum.get(code).getDesc();
    }
}
